package controllers.administrator;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import services.CustomerService;
import services.GalleryService;

import controllers.AbstractController;
import domain.Customer;
import domain.Gallery;

@Controller
@RequestMapping("/gallery/administrator")
public class GalleryAdministratorController extends AbstractController{

	//Services
		@Autowired
		private GalleryService galleryService;
		@Autowired
		private CustomerService customerService;
		
		//Constructor
		public GalleryAdministratorController(){
			super();
		}
		
		// Listing methods
		@RequestMapping(value = "/listAll", method = RequestMethod.GET)
		public ModelAndView list() {
			ModelAndView result;
			Collection<Gallery> galleries;

			galleries = galleryService.findAll();

			result = new ModelAndView("gallery/list");
			result.addObject("requestURI", "gallery/administrator/list.do");
			result.addObject("galleries", galleries);
			result.addObject("backURI", "/welcome/index.do");
			return result;
		}
		
		@RequestMapping(value = "/list", method = RequestMethod.GET)
		public ModelAndView listCustomer(@RequestParam int customerId) {
			ModelAndView result;
			Customer customer;
			Collection<Gallery> galleries;

			customer = customerService.findOne(customerId);
			galleries = galleryService.findByCustomer(customer);

			result = new ModelAndView("gallery/list");
			result.addObject("requestURI", "gallery/administrator/list.do");
			result.addObject("galleries", galleries);
			result.addObject("backURI", "/customer/administrator/list.do");
			return result;
		}
}
